// pages/uc/perfect_information/perfect_information.js
var dmNetwork = require('../../../utils/network.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    real_name: '',
    mobile: '',
    idnumber: '',
    detail_address: '',
    detail_address_flag: true,
    detail_unit_company: '',
    detail_unit_company_flag: true,
    detail_leaving_reason_flag: true,
    detail_nocontract_reason_flag: true,
    detail_leaving_reason: '',
    detail_nocontract_reason: '',
    real_name_enable_flag: true,
    mobile_enable_flag: true,
    idnumber_enable_flag: true,
    detail_address_enable_flag: true,
    is_protocol_supplement_info: 0,
    team_id: '',
    project_id: '',
    protocol_order_id: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('team_id:' + options.team_id)
    console.log('project_id:' + options.project_id)
    this.setData({
      team_id: options.team_id,
      is_protocol_supplement_info: options.is_protocol_supplement_info,
      // agreement_num: options.agreement_num,
      // protocol_type: options.protocol_type,
      project_id: options.project_id,
      protocol_order_id: options.protocol_order_id
    })
    var that = this;
    dmNetwork.get(dmNetwork.getauthentication, '', (res) => {
      if (res.data.errno == 0) {
        that.setData({
          real_name: res.data.data.real_name,
          mobile: res.data.data.mobile,
          idnumber: res.data.data.idnumber,
          detail_address: res.data.data.detail_address,
        })
      }

      if (res.data.data.real_name) {
        that.setData({
          real_name_enable_flag: false,
        })
      }

      if (res.data.data.mobile) {
        that.setData({
          mobile_enable_flag: false,
        })
      }

      if (res.data.data.idnumber) {
        that.setData({
          idnumber_enable_flag: false,
        })
      }

      if (res.data.data.detail_address) {
        that.setData({
          detail_address_enable_flag: false,
        })
      }

    })
  },

  real_name: function (e) {
    var value = e.detail.value;
    if (value) {
      this.setData({
        real_name: value
      })
    } else {
      this.setData({
        real_name: ''
      })
    }
  },

  mobile: function (e) {
    var value = e.detail.value;
    if (value) {
      this.setData({
        mobile: value
      })
    } else {
      this.setData({
        mobile: ''
      })
    }
  },

  idnumber: function (e) {
    var value = e.detail.value;
    if (value) {
      this.setData({
        idnumber: value
      })
    } else {
      this.setData({
        idnumber: ''
      })
    }
  },

  detail_address: function (e) {
    var value = e.detail.value;
    if (value) {
      this.setData({
        detail_address: value
      })
    } else {
      this.setData({
        detail_address: ''
      })
    }
  },
  bindDateChange(e) {
    this.setData({
      laborRelationsDate: e.detail.value
    })
  },
  blur_unit_company() {
    if (!this.data.detail_unit_company) {
      return
    }
    this.setData({
      detail_unit_company_flag: false
    })
  },
  on_unit_company_txt() {
    this.setData({
      detail_unit_company_flag: true
    })
  },
  blur_detail_address(){
    if (!this.data.detail_address) {
      return
    }
    this.setData({
      detail_address_flag: false
    })
  },
  on_detail_address_txt(){
    this.setData({
      detail_address_flag: true
    })
  },
  detail_unit_company: function (e) {
    var value = e.detail.value;
    if (value) {
      this.setData({
        detail_unit_company: value,
      })
    } else {
      this.setData({
        detail_unit_company: ''
      })
    }
  },



  blur_leaving_reason() {
    if (!this.data.detail_leaving_reason) {
      return
    }
    this.setData({
      detail_leaving_reason_flag: false
    })
  },
  on_leaving_reason_txt() {
    this.setData({
      detail_leaving_reason_flag: true
    })
  },
  detail_leaving_reason: function (e) {
    var value = e.detail.value;
    if (value) {
      this.setData({
        detail_leaving_reason: value,
      })
    } else {
      this.setData({
        detail_leaving_reason: ''
      })
    }
  },



  blur_nocontract_reason() {
    if (!this.data.detail_nocontract_reason) {
      return
    }
    this.setData({
      detail_nocontract_reason_flag: false
    })
  },
  on_nocontract_reason_txt() {
    this.setData({
      detail_nocontract_reason_flag: true
    })
  },
  detail_nocontract_reason: function (e) {
    var value = e.detail.value;
    if (value) {
      this.setData({
        detail_nocontract_reason: value,
      })
    } else {
      this.setData({
        detail_nocontract_reason: ''
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  loading: function () {
    wx.showLoading({
      title: '',
      mask: true,
    });
  },

  next: function () {
    if (this.data.is_protocol_supplement_info == 1) {
      if (!(this.data.real_name && this.data.mobile && this.data.idnumber && this.data.detail_address && this.data.detail_unit_company && this.data.laborRelationsDate && this.data.detail_leaving_reason && this.data.detail_nocontract_reason)) {
        return;
      }
    } else {
      if (!(this.data.real_name && this.data.mobile && this.data.idnumber && this.data.detail_address)) {
        console.log('111111' + '有未填写的项目')
        return;
      }
    }


    this.loading()
    var that = this;
    let params = {
      name: that.data.real_name,
      idnumber: that.data.idnumber,
      detail_address: that.data.detail_address,
      mobile: that.data.mobile
    }

    if (this.data.is_protocol_supplement_info == 1) {
      params.original_company = this.data.detail_unit_company
      params.leave_date = this.data.laborRelationsDate
      params.leave_reason = this.data.detail_leaving_reason
      params.no_leave_certify_reason = this.data.detail_nocontract_reason
      params.protocol_order_id = this.data.protocol_order_id
    }
    console.log(params);
    // return
    dmNetwork.get(dmNetwork.doauthentication, params, (res) => {
      wx.hideLoading()
      let navigateUrl = `../contract_signing_new/contract_signing_new?project_id=${that.data.project_id}&team_id=${that.data.team_id}`
      if (res.data.errno == 0) {
        wx.navigateTo({
          url: navigateUrl,
        })
      } else {
        wx.showToast({
          title: res.data.errmsg,
          icon: 'none'
        })
      }
    })
  }
})